package git.determinal.template.view;




import java.util.Map;

public class BetweenValue {
    private Object start;
    private Object end;

    public static BetweenValue getBetween(Object value, FieldType fieldType) {
        Map map = (Map)value;
        Object start = map.get("start");
        Object end = map.get("end");
        start = parse(start.toString(), fieldType);
        end = parse(end.toString(), fieldType);
        BetweenValue between = new BetweenValue(start, end);
        return between;
    }

    private static Object parse(String value, FieldType fieldType) {
        if (FieldType.INT.equal(fieldType)) {
            return new Integer(value);
        } else if (FieldType.FLOAT.equal(fieldType)) {
            return new Float(value);
        } else if (FieldType.DOUBLE.equal(fieldType)) {
            return new Double(value);
        } else if (FieldType.DATE_TIME.equal(fieldType)) {
            return value.indexOf(":") == -1 ? DateUtil.toDate(value) : DateUtil.toDateTime(value);
        } else if (FieldType.DATE.equal(fieldType)) {
            return DateUtil.toDate(value);
        } else {
            return FieldType.TIME.equal(fieldType) ? DateUtil.toTime(value) : value;
        }
    }

    public Object getStart() {
        return this.start;
    }

    public Object getEnd() {
        return this.end;
    }

    public void setStart(final Object start) {
        this.start = start;
    }

    public void setEnd(final Object end) {
        this.end = end;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof BetweenValue)) {
            return false;
        } else {
            BetweenValue other = (BetweenValue)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$start = this.getStart();
                Object other$start = other.getStart();
                if (this$start == null) {
                    if (other$start != null) {
                        return false;
                    }
                } else if (!this$start.equals(other$start)) {
                    return false;
                }

                Object this$end = this.getEnd();
                Object other$end = other.getEnd();
                if (this$end == null) {
                    if (other$end != null) {
                        return false;
                    }
                } else if (!this$end.equals(other$end)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof BetweenValue;
    }

    public int hashCode() {
        boolean PRIME = true;
        int result = 1;
        Object $start = this.getStart();
        result = result * 59 + ($start == null ? 43 : $start.hashCode());
        Object $end = this.getEnd();
        result = result * 59 + ($end == null ? 43 : $end.hashCode());
        return result;
    }

    public String toString() {
        return "BetweenValue(start=" + this.getStart() + ", end=" + this.getEnd() + ")";
    }

    public BetweenValue(final Object start, final Object end) {
        this.start = start;
        this.end = end;
    }

    public BetweenValue() {
    }
}

